package com.ruoyi.system.dl;

import com.qiniu.api.auth.digest.Mac;
import com.qiniu.api.config.Config;
import com.qiniu.api.rs.BatchCallRet;
import com.qiniu.api.rs.EntryPath;
import com.qiniu.api.rs.RSClient;
import com.ruoyi.system.mapper.ImagesMapper;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

public class DeleteImages {
    private static void Delete(List<String> images){
        Config.ACCESS_KEY = "3hJkzAepYkqZReMPIpAr2SOeohcpL9Z3DpCc-UPR";
        Config.SECRET_KEY = "nqsZjv3wOf35mnlBshNM7eT-aOaQVgX0zg4q3_DJ";
        Mac mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
        RSClient rs = new RSClient(mac);
        List<EntryPath> entries = new ArrayList<EntryPath>();
        images.forEach(image -> {
            EntryPath e1 = new EntryPath();
            e1.bucket = "traveldev";
            e1.key = image;
            entries.add(e1);
        });
        BatchCallRet bret = rs.batchDelete(entries);
        System.out.println(bret.ok());
    }
    public static void deleteIma(String foreignId,ImagesMapper imagesMapper){
        List<String> strings = imagesMapper.selectImages(foreignId);
        Delete(strings);
    }

    public static void DeleteOne(String image){
        Config.ACCESS_KEY = "3hJkzAepYkqZReMPIpAr2SOeohcpL9Z3DpCc-UPR";
        Config.SECRET_KEY = "nqsZjv3wOf35mnlBshNM7eT-aOaQVgX0zg4q3_DJ";
        Mac mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
        RSClient rs = new RSClient(mac);
        List<EntryPath> entries = new ArrayList<EntryPath>();
        EntryPath e1 = new EntryPath();
        e1.bucket = "traveldev";
        e1.key = image;
        entries.add(e1);
        BatchCallRet bret = rs.batchDelete(entries);
        System.out.println(bret.ok());
    }
}
